{# Modifier par Brice VICO #}

{% trans_default_domain 'FOSUserBundle' %}
<div class="container" style="margin-top:25px;">
<div class="col-md-4 col-md-offset-3">
    <form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register">
        {{form_errors(form)}}
        <div class="form-group">
            {{form_label(form.username)}}
            {{form_errors(form.username)}}
            {{form_widget(form.username, {'attr' : {'class' : 'form-control'}})}}
        <div>
        <div class="form-group">
            {{form_label(form.email)}}
            {{form_errors(form.email)}}
            {{form_widget(form.email, {'attr' : {'class' : 'form-control'}})}}
        <div>
        <div class="form-group">
            {{form_label(form.nom)}}
            {{form_errors(form.nom)}}
            {{form_widget(form.nom, {'attr' : {'class' : 'form-control'}})}}
        <div>
        <div class="form-group">
            {{form_label(form.prenom)}}
            {{form_errors(form.prenom)}}
            {{form_widget(form.prenom, {'attr' : {'class' : 'form-control'}})}}
        <div>
        <div class="form-group">
            {{form_label(form.plainPassword.first)}}
            {{form_errors(form.plainPassword.first)}}
            {{form_widget(form.plainPassword.first, {'attr' : {'class' : 'form-control'}})}}
        <div>
        <div class="form-group">
            {{form_label(form.plainPassword.second)}}
            {{form_errors(form.plainPassword.second)}}
            {{form_widget(form.plainPassword.second, {'attr' : {'class' : 'form-control'}})}}
        <div>
        <div class="form-group">
            <label for="type">Type :</label>
            <select class="form-control" name="type" id="type" onchange="afficherEtudiant(this);">
                <option value="u">Utilisateur non étudiant</option>
                <option value="t">Tuteur</option>
                <option value="e">Étudiant</option>
                <option value="s">Secrétaire</option>
            </select>
        </div>
        <div id="form-etudiant"></div>
        {{form_rest(form)}}
        <button type="submit" class="btn btn-success">Enregistrer</button>
    </form>
</div>
</div>


{#Code JavaScript permettant l'ajout d'un étudiant #}


<script type="text/javascript">
    function afficherEtudiant(mySelect)
    {
        var form = document.getElementById("form-etudiant");

        if(mySelect.selectedIndex == 2)
        {
            if(!form.hasChildNodes())
            {
                var divNumEtud = document.createElement("div");
                var labelNumEtud = document.createElement("label");
                var textLabelNumEtud = document.createTextNode("Numéro étudiant :");
                var numEtud = document.createElement("input");

                var divPhoto = document.createElement("div");
                var labelPhoto = document.createElement("label");
                var textLabelPhoto = document.createTextNode("Photo :");
                var photo = document.createElement("input");

                var divUe = document.createElement("div");
                var labelUe = document.createElement("label");
                var textLabelUe = document.createTextNode("Ue :");
                var ue = document.createElement("select");

                divNumEtud.className = "form-group";
                numEtud.type = "numeric";
                numEtud.className = "form-control";
                numEtud.name = "numEtud";

                divPhoto.className = "form-group";
                photo.type = "file";
                photo.className = "form-control";
                photo.name = "photo";

                divUe.className = "form-group";
                ue.className = "form-control";
                ue.name = "ue";

                form.appendChild(divNumEtud);
                divNumEtud.appendChild(labelNumEtud);
                labelNumEtud.appendChild(textLabelNumEtud);
                divNumEtud.appendChild(numEtud);

                form.appendChild(divPhoto);
                divPhoto.appendChild(labelPhoto);
                labelPhoto.appendChild(textLabelPhoto);
                divPhoto.appendChild(photo);

                form.appendChild(divUe);
                divUe.appendChild(labelUe);
                labelUe.appendChild(textLabelUe);
                divUe.appendChild(ue);

                {% set i = 0 %}
                {% for ue in listeUe %}
                    var option{{i}} = document.createElement("option");
                    option{{i}}.value = "{{ue.id}}";
                    option{{i}}.appendChild(document.createTextNode("{{ue.code}}"));
                    ue.appendChild(option{{i}});
                    {% set i = i + 1 %}
                {% endfor %}
            }
        }
        else
        {
            if(form.hasChildNodes())
            {
                form.innerHTML="";
            }
        }
    }
</script>
